<?php
/* @var $this yii\web\View */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model \common\models\LoginForm */

use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
?>
<?php $host = Yii::$app->request->hostInfo.'/' ;?>

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>文化云APP-发文</title>
    <link href="<?= $host;?>bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="<?= $host;?>images/style.css" rel="stylesheet">
    <link href="<?= $host;?>js/ueditor/themes/default/css/ueditor.css" rel="stylesheet">
    <link href="<?= $host;?>js/ueditor/third-party/codemirror/codemirror.css" rel="stylesheet">

</head>
<body>
<div class="container-fluid">
    <form id="w0" class="" action="#" method="post" enctype="multipart/form-data" style="">
        <input type="hidden" id="new_id" value="<?php if(isset($edit) && $edit == 1){echo $id;}else{echo 0;}?>" />
        <div class="fabiao-item">标题（5-30字）</div>
        <div class="fabiao-input">
            <input id="article-title" class="form-control" name="Article[title]" maxlength="30" type="text" value="<?php if(isset($edit) && $edit == 1){ echo $model->title;}?>">
        </div>
        <div class="fabiao-item">正文</div><a class="Upimges" href="javascript:uploadImg();"></a>
        <div id="editor" class="fabiao-text" style="">

        </div>
        <div class="fabiao-item">分类（选填）</div>
        <div class="fabiao-fenlei" onclick="fenlei();"><?php if(isset($model->catid) && !empty($model->catid)){ echo $catname;}else{echo "请选择分类";}?></div>
        <input id="article-category" class="form-control" name="Article[category]" type="hidden" value="<?php if(isset($edit) && $edit == 1){ echo $model->catid;}?>">

        <div class="fabiao-btn">
            <ul class="clearfix">
                <li class="fabiao"><button type="button" name="fabiao" onclick="tijiao(1);">发表</button></li>
                <li class="caogao"><button type="button" name="caogao" onclick="tijiao(0);">草稿</button></li>
                <li class="yulan"><button type="button" onclick="yulan();">预览</button></li>
                <li class="chanel"><a href="javascript:isSave();">取消</a></li>
            </ul>
        </div>
    </form>
</div>
<input type="hidden" value="0" id="isCaogao">
<div id="big"></div>
<div id="save">
    <p>提示</p>
    <p style="border-bottom: 1px solid #e5e5e5;">您当篇文章暂未保存，是否存为草稿</p>
    <p><span style="border-right:1px solid #e5e5e5;" onclick="quxiao(1)">是</span><span onclick="quxiao(3)">否</span></p>
</div>
<style type="text/css">
    #tishi{
        position: relative;
        display: table;
        margin: 0 auto;
        bottom:150px;
        padding: 5px 10px;
        color: #F6FAFD;
        border-radius: 5px;
        z-index:9999;
    }
    .Upimges{
        position: absolute;
        top: 143px;
        left: 250px;
        z-index:10000;
        display: inline;
        width: 30px;
        height: 20px;
        background:url("<?=$host; ?>js/ueditor/themes/default/images/icons.png") no-repeat -720px -80px;
    }
    .Upimges_f { position: fixed !important; left: 250px; top: 8px;}
    .fabiao-btn ul li.chanel a{
        display: block;
        background: url("<?=$host; ?>images/btn4_r.jpg") right no-repeat;
        border: 0 none;
        color: #fff;
        font-size: 14px;
        height: 30px;
        width: 100%;
        text-align: center;
        line-height: 30px;
        background-size: auto 30px;
        text-decoration:none;

    }
    button:focus{outline: none;}
    #big {
        display: none;
        background-color:#000;
        width: 100%;
        height: 100%;
        left: 0;
        top: 0;
        filter: alpha(opacity=50);
        opacity: 0.5;
        z-index: 12000;
        position: absolute;
    }
    #save{
        position: relative;
        display: none;
        margin: 0 auto;
        bottom:300px;
        padding: 5px 10px;
        color: #000000;
        z-index: 12002;
        border: 1px solid #F6FAFD;
        border-radius: 5px;
        background: #F6FAFD;
        background: #fff;
    }
    #save p{ text-align: center; margin: 0px; line-height: 30px;}
    #save p span{ float:left;padding:5px 50px;text-align: center;}
    #edui1_imagescale{display:none !important;} /*去除点击图片后出现的拉伸边框*/

</style>
<div id="tishi" style="display:none;"></div>
<?=Html::jsFile($host.'js/jquery.min.js')?>
<?=Html::jsFile($host.'js/ueditor/ueditor.config.js')?>
<?=Html::jsFile($host.'js/ueditor/ueditor.all.min.js')?>
<?=Html::jsFile($host.'js/ueditor/lang/zh-cn/zh-cn.js')?>
<?=Html::cssFile($host.'js/ueditor/themes/default/css/ueditor.css')?>
<script>
    jQuery(function($){
        $(window).scroll(function() {
            var dTop = $(window).scrollTop();
            if (dTop > 134) {
                $(".Upimges").addClass("Upimges_f");
            } else {
                $(".Upimges").removeClass("Upimges_f");
            }
        });
        $(document).not($("#save")).click(function(){
            $("#big").hide();
            $("#save").hide();
        });
    });
    setInterval("tijiao(3)",60000);
    var ue = UE.getEditor('editor',{
        toolbars:[['Undo', 'Redo','bold', 'italic', 'underline', 'removeformat', '|', 'blockquote', 'insertorderedlist', 'insertunorderedlist', '|']],
        wordCount:false,
        initialFrameWidth:'100%',
        initialFrameHeight:310,
        autoHeightEnabled:false,
        autoWidthEnabled:true,
        enableAutoSave: false,
        saveInterval: 500000000000,
    });
    ue.ready(function() {
        var text = '<?php echo $model->content."<Br>";?>';
        ue.setContent(text);
        $(".edui-editor-iframeholder").css({"-webkit-overflow-scrolling":"touch","overflow-y":"scroll"});
    });
    function uploadImg(){
        var content = ue.getContent();
        var n = (content.split('<img ')).length-1;
        if(n > 8 ){
            $("#tishi").html("最多可上传9张图").css("background-color","#000000").show().fadeOut(2000);
            return;
        }
        try{
            window.picture.choosePicture();
        } catch (e){alert(e);}
        try{
            WebViewJavascriptBridge.callHandler('choosePicture','',function(response) {
                document.getElementById("returnValue").value = response;
            });
        } catch (e){}
    }
    function imgUrl(url){
        ue.execCommand('insertHtml', '<br><img width="100%" src="'+url+'" />&nbsp;&nbsp;<br />');
        ue.setFocus();
        return;
    }
    function tijiao(status){
        var content = ue.getContent();
        var title = $("#article-title").val();
        var catid = $("#article-category").val();
        var zidong_save = 0;
        if(status == 3 && (ue.getContentTxt().length < 10 || title.length < 5)){/*自动保存草稿*/
            return;
        }else if(status == 3){
            zidong_save = 1;
            status = 0;
        }
        var id = $("#new_id").val();

        if(id > 0){
            var url = '<?=$host; ?>v1/publishpc/edit?id='+id;
        }else{
            var url = '<?=$host; ?>v1/publishpc/news';
        }
        $.ajax({
            type: 'post',
            url: url,
            cache:false,
            data: {title:title,content:content,status:status,catid:catid},
            headers : {'Accept':'application/json','access-token':'<?php echo $_GET['access-token'];?>'},
            success: function(data){
                var _data = data.data;
                $("#save").hide();
                if(_data.message == '文章发布成功!'){
                    try{
                        WebViewJavascriptBridge.callHandler('tiaozhuan',{"type":"1","status":_data.message},function(response) {
                            document.getElementById("returnValue").value = response;
                        });
                    } catch (e){alert(e);}
                    window.picture.tiaozhuan(1,_data.message);
                }else{
                    if(_data.message == '保存草稿成功!'){
                        $("#new_id").val(_data.id);
                    }
                    if(zidong_save &&　id < 1){
                        $("#isCaogao").val(1);
                    }
                    $("#tishi").html(_data.message).css("background-color","#000000").show().fadeOut(2000);return;
                }
            }
        })
    }
    function yulan(){
        var content = ue.getContent();
        var title = $("#article-title").val();
        if(title == '' || content == ''){
            $("#tishi").html("标题/内容不能为空").css("background-color","#000000").show().fadeOut(2000);
            return;
        }
        try{
            window.picture.yulan(title,content);
        } catch (e){alert(e);}
        try{
            WebViewJavascriptBridge.callHandler('yulanIos',{"title":title,"content":content},function(response) {
                //document.getElementById("returnValue").value = response;
            });
        } catch (e){}
    }
    function test(){
        var content = ue.getContent();
        ue.setContent(content);
        $(".edui-editor-iframeholder").css({"-webkit-overflow-scrolling":"touch","overflow-y":"scroll"});
    }
    function isSave(){
        var id = $("#new_id").val();
        var content = ue.getContent();
        var title = $("#article-title").val();
        if(($("#isCaogao").val() == 1) || (id < 1 && content.length > 9 && title.length > 4)) {
            document.getElementById('big').style.display = 'block';
            document.getElementById('save').style.display = 'table';
        }else{
            quxiao(0);
        }
    }
    function quxiao(type){
            $("#big").hide();
            $("#save").hide();
            if(type == 1){
                $("#isCaogao").val(0);
                tijiao(0);
                return;
            }else if(type == 3){
                //删除保存的草稿
                if($("#isCaogao").val() == 1){
                    var id = $("#new_id").val();
                    var url = '<?=$host; ?>v1/publishpc/del?id='+id;
                    $.ajax({
                        type: 'get',
                        url: url,
                        cache:false,
                        headers : {'Accept':'application/json','access-token':'<?php echo $_GET['access-token'];?>'},
                        success: function(data){
                        }
                    });
                }
            }
        try{
            WebViewJavascriptBridge.callHandler('tiaozhuan',{"type":type},
                function(response) {

                });
        } catch (e){}
        window.picture.tiaozhuan(type,"");
    }
    function fenlei(){
        try{
            window.fenleiObj.fenlei();
        } catch (e){alert(e);}
        /*try{
            WebViewJavascriptBridge.callHandler('fenlei');
        } catch (e){}*/

    }
    function fenleiVal(catid,catname){
        $("#tishi").html(catid).css("background-color","#000000").show().fadeOut(1000);
        $("#tishi").html(catname).css("background-color","#000000").show().fadeOut(2000);
        $(".fabiao-fenlei").html(catname);
        $("#article-category").val(catid);
        return;
    }
    function setupWebViewJavascriptBridge(callback) {
        if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); }
        if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); }
        window.WVJBCallbacks = [callback];
        var WVJBIframe = document.createElement('iframe');
        WVJBIframe.style.display = 'none';
        WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__';
        document.documentElement.appendChild(WVJBIframe);
        setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
    }

    setupWebViewJavascriptBridge(function(bridge) {
        /* 这里注册Native 要调用的js 功能。*/
        bridge.registerHandler('uploadImage', function(data, responseCallback) {
            responseCallback(data);
            imgUrl(data);
        });
        bridge.registerHandler('isSave_IOS', function(data, responseCallback) {
            responseCallback(data);
            isSave();
        });
        bridge.registerHandler('isTest', function(data, responseCallback) {
            responseCallback(data);
            test();
        });
        bridge.registerHandler('isFenleiVal', function(data, responseCallback) {
            responseCallback(data);
            fenleiVal(data);
        });
        /* 如果要有其他Native 调用的js 功能，在这里按照上面的格式添加。*/
    })
</script>
<Br>
</body>
</html>


